package pw.yumc.Residence.commandsub;

import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.protection.ResidenceManager;

import cn.citycraft.PluginHelper.commands.BaseCommand;
import pw.yumc.Residence.ResidenceMain;

public class CommandList extends BaseCommand {
    ResidenceMain plugin;

    public CommandList(final ResidenceMain plugin) {
        super("l");
        this.plugin = plugin;
        setOnlyPlayerExecutable();
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        final Player player = (Player) sender;
        final ResidenceManager rmanager = plugin.getResidenceManager();
        int page = 1;
        try {
            if (args.length > 0) {
                page = Integer.parseInt(args[args.length - 1]);
            }
        } catch (final Exception ex) {
        }
        switch (args.length) {
        case 0:
            rmanager.listResidences(player);
            return;
        case 1:
            try {
                Integer.parseInt(args[0]);
                rmanager.listResidences(player, page);
            } catch (final Exception ex) {
                rmanager.listResidences(player, args[0]);
            }
            return;
        case 2:
            rmanager.listResidences(player, args[0], page);
            return;
        }
    }

}
